﻿CMAKE_MINIMUM_REQUIRED(VERSION 3.15.0 FATAL_ERROR)


PROJECT(IDA)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置启用QT编译器
SET(CMAKE_AUTOMOC ON)
SET(CMAKE_AUTOUIC ON)
SET(CMAKE_AUTORCC ON)

# 包含当前目录
SET(CMAKE_INCLUDE_CURRENT_DIR ON)

# 设置项目库文件前缀和后缀，设置项目库文件的输出目录
IF(CMAKE_BUILD_TYPE  MATCHES "Debug")
    SET(PROJECT_BUILD_TYPE_POSTFIX "d")
ELSE()
    SET(PROJECT_BUILD_TYPE_POSTFIX "")
ENDIF()

# 设置项目输出目录
SET(PROJECT_OUTPUT_DIR ${PROJECT_SOURCE_DIR}/output)
SET(PROJECT_OUTPUT_BIN_DIR ${PROJECT_OUTPUT_DIR}/bin${PROJECT_BUILD_TYPE_POSTFIX})
SET(LIBRARY_OUTPUT_PATH ${PROJECT_OUTPUT_BIN_DIR})
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_OUTPUT_BIN_DIR})

#=========================引入外部依赖库=======================================
# 设置第三方库目录
SET(LIBRARY_THIRDPARTY_DIR ${PROJECT_SOURCE_DIR}/ThirdpartyLibs)

# 设置第三方依赖库的目录
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")

ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Windows")
    SET(Qt5_DIR D:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5)
    IF(NOT EXISTS ${Qt5_DIR})        
        SET(Qt5_DIR //192.168.1.215/SharedFolder/ThirdpartyLibs/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5)
    ENDIF()
    SET(SUBDIR_THIRDPARTY_DIR ${LIBRARY_THIRDPARTY_DIR}/Libs/windows-x86_64)
    SET(MODULE_VTK_DIR ${SUBDIR_THIRDPARTY_DIR}/vtk)
    SET(MODULE_ElaWidgetTools_DIR ${SUBDIR_THIRDPARTY_DIR}/ElaWidgetTools)
    SET(MODULE_QCustomPlot_DIR ${SUBDIR_THIRDPARTY_DIR}/QCustomPlot)
    SET(MODULE_PYTHON_DIR ${SUBDIR_THIRDPARTY_DIR}/python37)

ENDIF()

MESSAGE(STATUS "{${PROJECT_NAME}} QT_Core目录 = ${Qt5Core_DIR}")

# 检查第三方依赖库目录是否存在
IF(NOT EXISTS ${Qt5_DIR})        
    MESSAGE(SEND_ERROR "Please specified Qt5Config.cmake location!~ Qt5_DIR = ${Qt5_DIR}")
ENDIF()
IF(NOT EXISTS ${MODULE_VTK_DIR})        
    MESSAGE(SEND_ERROR "Please specified Module directory!~  MODULE_VTK_DIR = ${MODULE_VTK_DIR}")
ENDIF()

# 设置第三方依赖库的头文件目录
SET(LIBRARY_VTK_INCLUDE ${MODULE_VTK_DIR}/include)

# 设置第三方依赖库库文件目录，并检查是否存在额
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
    #Set FastCAE Linux Dependencies Libraries Path

    #VTK
    SET(VTK_SO_DIR ${VTK_DIR2}/lib)
    IF(NOT EXISTS ${VTK_SO_DIR})
        MESSAGE(SEND_ERROR "VTK_SO_DIR is null, please specified VTK so directory!~")
    ENDIF()

ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Windows")

    #vld路径设置
    SET(VLD_DIR ${SUBDIR_THIRDPARTY_DIR}/vld-2.5.1)
    INCLUDE_DIRECTORIES(${VLD_DIR}/include)
    FILE(COPY ${VLD_DIR}/bin/vld_x64.dll  DESTINATION ${PROJECT_OUTPUT_BIN_DIR})
    
    #VTK
    #SET(MODULE_VTK_DIR D:/WorkSpace/IDA_desk_app/ThirdpartyLibs/Libs/windows-x86_64/vtk)
    IF(NOT EXISTS ${MODULE_VTK_DIR})        
        MESSAGE(SEND_ERROR "Please specified Module directory!~  MODULE_VTK_DIR = ${MODULE_VTK_DIR}")
    ENDIF()

    SET(LIBRARY_VTK_INCLUDE ${MODULE_VTK_DIR}/include)
    SET(LIBRARY_VTK_LIBDIR ${MODULE_VTK_DIR}/lib${PROJECT_BUILD_TYPE_POSTFIX})
    SET(LIBRARY_VTK_BINDIR ${MODULE_VTK_DIR}/bin${PROJECT_BUILD_TYPE_POSTFIX})
    FILE(GLOB LIBRARY_VTK_LIBS "${LIBRARY_VTK_LIBDIR}/*.lib")
    FILE(GLOB LIBRARY_VTK_BINS "${LIBRARY_VTK_BINDIR}/*.dll")
    IF(NOT LIBRARY_VTK_LIBS)        
        MESSAGE(SEND_ERROR "Please specified lib directory!~ LIBRARY_VTK_LIBDIR=${LIBRARY_VTK_LIBDIR}")
    ENDIF()
    IF(NOT LIBRARY_VTK_BINS)        
        MESSAGE(SEND_ERROR "Please specified bin directory!~ LIBRARY_VTK_BINDIR=${LIBRARY_VTK_BINDIR}")
    ENDIF()

    # UI组件库
    SET(LIBRARY_ElaWidgetTools_INCLUDE ${MODULE_ElaWidgetTools_DIR}/include)
    SET(LIBRARY_ElaWidgetTools_LIBDIR ${MODULE_ElaWidgetTools_DIR}/lib)
    SET(LIBRARY_ElaWidgetTools_BINDIR ${MODULE_ElaWidgetTools_DIR}/bin${PROJECT_BUILD_TYPE_POSTFIX})
    FILE(GLOB LIBRARY_ElaWidgetTools_LIBS "${LIBRARY_ElaWidgetTools_LIBDIR}/*.lib")
    FILE(GLOB LIBRARY_ElaWidgetTools_BINS "${LIBRARY_ElaWidgetTools_BINDIR}/*.dll")
    IF(NOT LIBRARY_ElaWidgetTools_BINS)        
        MESSAGE(SEND_ERROR "Please specified bin directory!~ LIBRARY_ElaWidgetTools_BINS=${LIBRARY_ElaWidgetTools_BINS}")
    ENDIF()

    # QCustomPlot
    SET(LIBRARY_QCustomPlot_INCLUDE ${MODULE_QCustomPlot_DIR}/include)
    SET(LIBRARY_QCustomPlot_LIBDIR ${MODULE_QCustomPlot_DIR}/lib${PROJECT_BUILD_TYPE_POSTFIX})
    SET(LIBRARY_QCustomPlot_BINDIR ${MODULE_QCustomPlot_DIR}/bin${PROJECT_BUILD_TYPE_POSTFIX})
    FILE(GLOB LIBRARY_QCustomPlot_LIBS "${LIBRARY_QCustomPlot_LIBDIR}/*.lib")
    FILE(GLOB LIBRARY_QCustomPlot_BINS "${LIBRARY_QCustomPlot_BINDIR}/*.dll")
    IF(NOT LIBRARY_QCustomPlot_BINS)        
        MESSAGE(SEND_ERROR "Please specified bin directory!~ LIBRARY_QCustomPlot_BINS=${LIBRARY_QCustomPlot_BINS}")
    ENDIF()
ENDIF()


ADD_SUBDIRECTORY(BaseModule)
ADD_SUBDIRECTORY(IDAMainProgram)
ADD_SUBDIRECTORY(PostProcessing)
ADD_SUBDIRECTORY(GenerateReport)


# 复制第三方依赖库文件
MESSAGE(STATUS "Start copying third-party dependent library files.")
FILE(COPY ${LIBRARY_VTK_BINS}
          DESTINATION ${PROJECT_OUTPUT_BIN_DIR})

# 复制qt插件文件
MESSAGE(STATUS "Start copying qt plugins files.")
FILE(COPY ${Qt5_DIR}/../../../plugins/platforms
          ${Qt5_DIR}/../../../plugins/imageformats
          ${Qt5_DIR}/../../../plugins/platformthemes
          ${Qt5_DIR}/../../../plugins/styles
          #${Qt5_DIR}/../../../plugins/audio
          DESTINATION ${PROJECT_OUTPUT_BIN_DIR}/plugins)

# 复制qwebengine翻译文件
#MESSAGE(STATUS "Start copying qwebengine translations files.")
#FILE(COPY ${Qt5_DIR}/../../../translations/qtwebengine_locales/zh-CN.pak
#          ${Qt5_DIR}/../../../translations/qtwebengine_locales/en-US.pak
#          DESTINATION ${PROJECT_OUTPUT_BIN_DIR}/translations/qtwebengine_locales)

# 复制qt库文件
MESSAGE(STATUS "Start copying resource files and QT library files.")
FILE(COPY ${Qt5_DIR}/../../../bin/Qt5Core${PROJECT_BUILD_TYPE_POSTFIX}.dll
          ${Qt5_DIR}/../../../bin/Qt5Gui${PROJECT_BUILD_TYPE_POSTFIX}.dll
          ${Qt5_DIR}/../../../bin/Qt5Widgets${PROJECT_BUILD_TYPE_POSTFIX}.dll
          #${Qt5_DIR}/../../../bin/Qt5Xml${PROJECT_BUILD_TYPE_POSTFIX}.dll
          #${Qt5_DIR}/../../../bin/Qt5Network${PROJECT_BUILD_TYPE_POSTFIX}.dll
          #${Qt5_DIR}/../../../bin/Qt5WebChannel${PROJECT_BUILD_TYPE_POSTFIX}.dll
          #${Qt5_DIR}/../../../bin/Qt5Quick${PROJECT_BUILD_TYPE_POSTFIX}.dll
          #${Qt5_DIR}/../../../bin/Qt5Qml${PROJECT_BUILD_TYPE_POSTFIX}.dll
          #${Qt5_DIR}/../../../bin/Qt5WebEngineCore${PROJECT_BUILD_TYPE_POSTFIX}.dll
          #${Qt5_DIR}/../../../bin/Qt5WebEngineWidgets${PROJECT_BUILD_TYPE_POSTFIX}.dll
          #${Qt5_DIR}/../../../bin/Qt5WebView${PROJECT_BUILD_TYPE_POSTFIX}.dll
          #${Qt5_DIR}/../../../bin/Qt5QuickWidgets${PROJECT_BUILD_TYPE_POSTFIX}.dll
          #${Qt5_DIR}/../../../bin/Qt5QmlModels${PROJECT_BUILD_TYPE_POSTFIX}.dll
          ${Qt5_DIR}/../../../bin/Qt5PrintSupport${PROJECT_BUILD_TYPE_POSTFIX}.dll
          #${Qt5_DIR}/../../../bin/Qt5Positioning${PROJECT_BUILD_TYPE_POSTFIX}.dll
          #${Qt5_DIR}/../../../bin/Qt5Multimedia${PROJECT_BUILD_TYPE_POSTFIX}.dll
          #${Qt5_DIR}/../../../bin/QtWebEngineProcess${PROJECT_BUILD_TYPE_POSTFIX}.exe
          ${Qt5_DIR}/../../../bin/libEGL${PROJECT_BUILD_TYPE_POSTFIX}.dll
          ${Qt5_DIR}/../../../bin/libGLESv2${PROJECT_BUILD_TYPE_POSTFIX}.dll
          #${Qt5_DIR}/../../../resources
          DESTINATION ${PROJECT_OUTPUT_BIN_DIR})


# 复制python配置文件
MESSAGE(STATUS "Start copying Config Files.")
FILE(COPY ${PROJECT_SOURCE_DIR}/Resources/ConfigFiles/qt.conf
          DESTINATION ${PROJECT_OUTPUT_BIN_DIR})


# 复制python脚本文件、几何模型文件和配置文件
MESSAGE(STATUS "Start copying example Files.")
FILE(COPY ${PROJECT_SOURCE_DIR}/Resources/examples
          DESTINATION ${PROJECT_OUTPUT_DIR})
